package com.situ.web;

import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 

public class TimeServlent extends HttpServlet{ //接口
	@Override
	//HttpServletRequest请求对象，HttpServletResponse resp回应对象
	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		Date date = new Date();//java.util.Date
		SimpleDateFormat simpleDateFormat  //当前日期改为中国格式
		= new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
		String nowDate = simpleDateFormat.format(date);
		
		//信息返回浏览器
		PrintWriter printWriter = resp.getWriter();
		printWriter.println("<p>" + nowDate + "<p>");  //打印出
		printWriter.close();
		
		//无法直接访问，必须配置
		//web.xml里面配置
	}
}
